package com.herench.bs.control;


import com.herench.bs.agent.BillInHosAgent;
import com.herench.bs.dao.IUserDao;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.HashMap;
import java.util.Map;

@Controller
@CrossOrigin
@RequestMapping("/bill")
public class BillInHosController {
    @Autowired
    private IUserDao userDao;

    @Autowired
    private BillInHosAgent billInHosAgent;


    @RequestMapping("/pat")
    public @ResponseBody
    Map<String, Object> pat(HttpServletRequest request, HttpServletResponse response) throws Exception {
        Map<String, Object> res = new HashMap<>();
        String phone = request.getParameter("phone");
        String idCard = request.getParameter("idCard");
        String billDate = request.getParameter("billDate");
//        Date date = new Date();
//        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
//        String dateNow = sdf.format(date);
//        if(billDate.equals("") || billDate==null){
//            billDate = dateNow;
//        }
//        String idCard = "120102196206230710";
//        String billDate = "2018-12-03";
        Map<String, Object> params = new HashMap<>();
        params.put("username", phone);
        params.put("idNo", idCard);
        params.put("billDate", billDate);
//        billInHosAgent.getPat(params);
//        Map<String, Object> resMap = new HashMap<>(16);
//        resMap = billInHosAgent.getPat(params);
//        if (Dialect.getSuccessfulState().equals(resMap.get(ResponseMessage.RES_CODE))) {
//            res.putAll(resMap);
//            res.put(ResponseMessage.RES_CODE, "0");
//            res.put(ResponseMessage.MESSAGE_IN, "查询成功");
//            res.put(ResponseMessage.MESSAGE, "查询成功");
//            res.put(ResponseMessage.MESSAGE_OUT, "查询成功");
//        } else {
//            res.put(ResponseMessage.RES_CODE, "-1");
//            res.put(ResponseMessage.MESSAGE_IN, "查询失败");
//            res.put(ResponseMessage.MESSAGE, "查询失败");
//            res.put(ResponseMessage.MESSAGE_OUT, "查询失败");
//        }
        return billInHosAgent.getPat(params);
    }

    @RequestMapping("/list")
    public @ResponseBody
    Map<String, Object> list(HttpServletRequest request, HttpServletResponse response)throws Exception{
        Map<String, Object> res = new HashMap<>();
        String phone = request.getParameter("phone");
        String idCard = request.getParameter("idCard");
        String billDate = request.getParameter("date");
//        String idCard = "120102196206230710";
//        String billDate = "2018-12-03";
        Map<String, Object> params = new HashMap<>();
        params.put("username", phone);
        params.put("idNo", idCard);
        params.put("billDate", billDate);
//        billInHosAgent.getList(params);
//        Map<String, Object> resMap = new HashMap<>(16);
//        resMap = billInHosAgent.getList(params);
//        if (Dialect.getSuccessfulState().equals(resMap.get(ResponseMessage.RES_CODE))) {
//            res.putAll(resMap);
//            res.put(ResponseMessage.RES_CODE, "0");
//            res.put(ResponseMessage.MESSAGE_IN, "查询成功");
//            res.put(ResponseMessage.MESSAGE, "查询成功");
//            res.put(ResponseMessage.MESSAGE_OUT, "查询成功");
//        } else {
//            res.put(ResponseMessage.RES_CODE, "-1");
//            res.put(ResponseMessage.MESSAGE_IN, "查询失败");
//            res.put(ResponseMessage.MESSAGE, "查询失败");
//            res.put(ResponseMessage.MESSAGE_OUT, "查询失败");
//        }
        return billInHosAgent.getList(params);
    }

//    @RequestMapping("/detail")
//    public @ResponseBody
//    Map<String, Object> detail(HttpServletRequest request, HttpServletResponse response)throws Exception{
//        Map<String, Object> res = new HashMap<>();
//        String phone = request.getParameter("phone");
////        String idCard = request.getParameter("idCard");
////        String billDate = request.getParameter("date");
////        String itemClassCode = request.getParameter("itemClassCode");
//        String idCard = "120102196206230710";
//        String billDate = "2018-12-03";
//        String itemClassCode = "K";
//        Map<String, Object> params = new HashMap<>();
//        params.put("username", phone);
//        params.put("idNo", idCard);
//        params.put("billDate", billDate);
//        params.put("itemClassCode", itemClassCode);
////        billInHosAgent.getDetail(params);
////        Map<String, Object> resMap = new HashMap<>(16);
////        resMap = billInHosAgent.getDetail(params);
////        if (Dialect.getSuccessfulState().equals(resMap.get(ResponseMessage.RES_CODE))) {
////            res.putAll(resMap);
////            res.put(ResponseMessage.RES_CODE, "0");
////            res.put(ResponseMessage.MESSAGE_IN, "查询成功");
////            res.put(ResponseMessage.MESSAGE, "查询成功");
////            res.put(ResponseMessage.MESSAGE_OUT, "查询成功");
////        } else {
////            res.put(ResponseMessage.RES_CODE, "-1");
////            res.put(ResponseMessage.MESSAGE_IN, "查询失败");
////            res.put(ResponseMessage.MESSAGE, "查询失败");
////            res.put(ResponseMessage.MESSAGE_OUT, "查询失败");
////        }
//        return billInHosAgent.getDetail(params);
//    }

}
